const { think } = require('thinkjs');
const randomstring = require('randomstring');
const moment = require('moment');
// const { OpenAI } = require('@langchain/openai');

module.exports = class extends think.Controller {
  async jobAction() {
    const id = this.get('id');
    // const staff = await this.model('staff_info').where({ id: id }).find();
    // const baseInfo = await this.model('staff_base')
    //   .where({ info_id: id })
    //   .find();
    // if (think.isEmpty(baseInfo)) {
    //   this.assign('baseInfo', null);
    // } else {
    //   this.assign('baseInfo', baseInfo);
    // }
    // this.assign('name', staff.name);
    // this.assign('mobile', staff.mobile);

    // const model = new OpenAI(); // 记得在环境变量中配置你的OpenAI Key
    // const resA = await model.call('为一个披萨饼餐厅起一个好的名字。');
    // console.log(resA);
    return this.display();
  }

  async submitAction() {
    const value = this.post();
    // const code = this.post('smscode');
    // const hasCode = await this.model('sms_code')
    //   .where({ phone: value.phone, code: code, status: 0 })
    //   .find();
    // if (think.isEmpty(hasCode) && code !== '1235') {
    //   return this.fail(408, '验证码错误');
    // }
    value.create_time = ['exp', 'CURRENT_TIMESTAMP()'];
    const baseInfo = await this.model('staff_base')
      .where({ info_id: value.info_id })
      .find();
    if (think.isEmpty(baseInfo)) {
      await this.model('staff_base').add(value);
    } else {
      await this.model('staff_base').where({ id: baseInfo.id }).update(value);
    }

    return this.success();
  }
};
